<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="./css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="css/app.css" />
		<link rel="stylesheet" type="text/css" href="./css/mui.picker.css" />
		<link rel="stylesheet" type="text/css" href="css/iconfont.css" />
		<link rel="stylesheet" type="text/css" href="./css/meterReading.css" />
		<link rel="stylesheet" type="text/css" href="css/loading.css" />
		<script src="js/mui.min.js" type="text/javascript" charset="utf-8"></script>
		<style type="text/css">
			.mui-content .mui-input-group .selectWaterId {
				/* border: 0.0625rem solid red; */
				margin-top: 0.3125rem;
				height: 2.8125rem;
				width: 100%;
			}

			.mui-content .mui-input-group .selectWaterId span {
				margin-left: 0.8125rem;
				margin-top: 0.3125rem;
			}

			.mui-content .mui-input-group .selectWaterId select {
				/* border: 0.0625rem solid yellow; */
				background-color: lightgray;
				width: 65%;
				color: gray;
				font-size: 1.125rem;
			}

			.mui-content .btnQuiry {
				/* border: 0.0625rem solid red; */
				/* margin-bottom: 0.3125rem; */
			}
		</style>
	</head>

	<body onload="body_onload()">
		<div class="mui-content">
			<!-- 查询用户信息 -->
			<form class="mui-input-group">
				<div class="mui-plus-visible usernameLine">
					<label id="usernames">用户号：</label>
					<input id="userId" type="number" class="mui-input-clear" placeholder="请输入用户号">

					<!-- 二维码扫描获取用户信息 -->
					<a id="qrCode" href="javascript:;"><img src="icon/scanning.png"></a>

					<a id="confirm" href="javascript:;"><img src="./images/arrow1.png"></a>
				</div>
				<!-- 需要修改 -->
				<!-- <div class="select mui-content-padded">
					<span class="waterIdName">水表号：</span>
					<select id="waterId" class="mui-btn mui-btn-block">
						<option id="isWaterId" value="0">请选择水表号</option>
					</select>
				</div> -->
				<div class="selectWaterId">
					<span>水表号：</span>
					<select id="waterId">
						<option id="isWaterId" value="0">请选择水表号</option>
					</select>
				</div>

				<div class="mui-button-row btnQuiry">
					<button id="previous_household" type="button" class="mui-btn mui-btn-primary mui-btn-block mui-btn-outlined">上一户</button>
					<button id="quiryData" type="button" class="mui-btn mui-btn-primary mui-btn-block">查询</button>
					<button id="next_household" type="button" class="mui-btn mui-btn-primary mui-btn-block mui-btn-outlined">下一户</button>
				</div>
			</form>
			<div class="userWaterInfos">
				<!-- 设置放置查询结果的临时容器 -->
				<div class="result_storage">
					<input type="number" name="" id="userId_sto" value="" />
					<input type="text" name="" id="waterId_sto" value="" />
				</div>

				<div class="headers queryResult">
					<div class="legend"></div>
					<div class="legendTo">查询结果</div>
				</div>
				<div class="dataInfo">
					<div class="username">
						<div class="userNameIcon">
							<span class="icon iconfont">&#xe685;</span>
						</div>
						<div class="userdata">
							<span class="dataName">用户名</span>
							<span class="detailData" id="userName"></span>
						</div>
					</div>
					
					<div class="username">
						<div class="userNameIcon">
							<span class="icon iconfont">&#xe61c;</span>
						</div>
						<div class="userdata">
							<span class="dataName">抄表员</span>
							<span class="detailData" id="meterReading"></span>
						</div>
					</div>
					<div class="username">
						<div class="userNameIcon">
							<span class="icon iconfont">&#xe604;</span>
						</div>
						<div class="userdata">
							<span class="dataName">出厂号</span>
							<!--oldUserId  olduserid-->
							<span class="detailData" id="waterfactorid"></span>
						</div>
					</div>
					<div class="username">
						<div class="userNameIcon">
							<span class="icon iconfont">&#xe66e;</span>
						</div>
						<div class="userdata">
							<span class="dataName">抄表年月</span>
							<span class="detailData" id="meterReadingDate"></span>
						</div>
					</div>
					<div class="username">
						<div class="userNameIcon">
							<span class="icon iconfont">&#xe684;</span>
						</div>
						<div class="userdata">
							<span class="dataName">本月起码</span>
							<span class="detailData" id="lastMonthCode"></span>
						</div>
					</div>
					
					<div class="username">
						<div class="userNameIcon">
							<span class="icon iconfont">&#xe6c5;</span>
						</div>
						<div class="userdata">
							<span class="dataName">用水吨位</span>
							<span class="detailData" id="waterTonnage"></span>
						</div>
					</div>
					<div class="queryresult-address">
						<span class="queryresult-address-name">
							地址：
						</span>
						<span id="useraddress"></span>
					</div>
				</div>
				<div class="headers inputMeterR">
					<div class="legend"></div>
					<div class="legendTo inputNum">录入抄码数</div>
				</div>
				<form class="mui-input-group entryInformation">
					<div class="mui-input-row">
						<label>本月抄码：</label>
						<input id="thisMonth" type="number" class="mui-input-clear" placeholder="输入本月抄码数">
					</div>
					<div class="another-info">
						<ul class="mui-table-view mui-table-view-chevron">
							<li class="mui-table-view-cell mui-collapse"><a class="mui-navigate-right" href="#">其他抄码</a>
								<ul class="mui-table-view mui-table-view-chevron">
									<li class="mui-table-view-cell">
										<div class="mui-input-row">
											<label>估算吨位：</label>
											<input id="estimateTonnage" type="number" value="0" class="mui-input-clear" placeholder="输入估计吨位数">
										</div>
									</li>
									<li class="mui-table-view-cell">
										<div class="mui-input-row">
											<label>检前抄码：</label>
											<input id="pre" type="number" value="0" class="mui-input-clear" placeholder="输入检前抄码数">
										</div>
									</li>
									<li class="mui-table-view-cell">
										<div class="mui-input-row">
											<label>检后抄码：</label>
											<input id="after" type="number" value="0" class="mui-input-clear" placeholder="输入检后抄码数">
										</div>
									</li>
									<li class="mui-table-view-cell">
										<div class="mui-input-row">
											<label>增减吨位：</label>
											<input id="offSet" type="number" value="0" class="mui-input-clear" placeholder="输入增减吨位数">
										</div>
									</li>
									<li class="mui-table-view-cell">
										<div class="mui-input-row">
											<label>备注：</label>
											<input id="memo" type="text" value="" class="mui-input-clear" placeholder="输入备注信息">
										</div>
									</li>
								</ul>
							</li>
						</ul>
					</div>
					
					<span id="prompt">
						提示：增减量中正数代表增加吨位，负数代表减免吨位
					</span>
					<div class="mui-button-row submitBtn">
						<button id="submit" type="button" class="mui-btn mui-btn-primary" onclick="return false;">保存</button>
					</div>
				</form>
			</div>
			<!-- <div class="blank">
				
			</div> -->
		</div>

		<script src="js/qrCode.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/jquery-2.1.1.min.js" type="text/javascript" charset="utf-8"></script>
		<!-- <script src="http://103.59.149.116:6198/hcys/js/mapi.js" type="text/javascript" charset="utf-8"></script> -->
		<script src="js/Mobile.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/app.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/loading.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			mui.init({
				keyEventBind: {
					backbutton: false //关闭back按键监听  
				}
			});

			// 按两次返回键退出APP
			function body_onload() {
				mui.plusReady(function() {
					plus.key.addEventListener("backbutton", function() {
						mui.toast('再按一次退出应用', {
							duration: 'long',
							type: 'div'
						});
						setTimeout(function() {
							plus.key.removeEventListener("backbutton", function() {});
						}, 3000);
						plus.key.addEventListener("backbutton", function() {
							plus.runtime.quit();
							plus.webview.close(plus.webview.all());
						}, false);
					}, false);
				})
			}

			// 调用键盘时webview被挤压的问题
			// var originalHeight = document.documentElement.clientHeight || document.body.clientHeight;
			// window.onresize = function() {
			// 	//软键盘弹起与隐藏  都会引起窗口的高度发生变化
			// 	var resizeHeight = document.documentElement.clientHeight || document.body.clientHeight;
			// 	if (resizeHeight * 1 < originalHeight * 1) { //resizeHeight<originalHeight证明窗口被挤压了
			// 		plus.webview.currentWebview().setStyle({
			// 			height: originalHeight
			// 		});
			// 	}
			// }


			// 监听二维码点击事件
			mui(".usernameLine").on("tap", "#qrCode", function() {
				var myStorage = JSON.parse(localStorage.getItem("users"));
				var glbToken = myStorage.glbToken;
				if (checkToken(glbToken).status == "ok") {
					createWithoutTitle('barcode.html', {
						titleNView: {
							type: 'float',
							backgroundColor: 'rgba(123, 255, 255, 0.3)',
							titleText: '请扫码',
							titleColor: '#FFFFFF',
							autoBackButton: true
						}
					});
				} else {
					app.setState({});
					plus.webview.getLaunchWebview().show("pop-in");
					setTimeout(function() {
						alert("此账号已在其他设备登录,请重新登录!");
						localStorage.clear();
						plus.runtime.restart();
					}, 30);
				}
			});

			// 二维码扫描模块
			function scaned(t, r, f) {
				if (r.substr(0, 2) && r.substr(-1) == '#') {
					var result = r.split((','))
					var _userId = result[0].substr(2);
					var _waterId = result[1]
					var _username = result[2].substr(0, result[2].length - 1);
					$("#userId").val(_userId);
					// 移除添加的option
					$("#waterId option[value != 0]").remove();
					// 将水表号添加到列表中
					$("#waterId").append("<option selected='selected' value='1'>" + _waterId + "</option>");
				} else {
					plus.nativeUI.alert("请您按规范扫描二维码！")
					return false;
				}
			}

			mui.plusReady(function() {
				// mui.fire(plus.webview.getWebviewById("minelist.html"),"Token",{glbToken:glbToken})
				mui(".usernameLine").on("tap", "#confirm", function() {
					var myStorage = JSON.parse(localStorage.getItem("users"));
					var glbToken = myStorage.glbToken;
					if (checkToken(glbToken).status == "ok") {
						mui.openWindow({
							url: "userList.html",
							id: "userList.html"
						})
					} else {
						app.setState({});
						plus.webview.getLaunchWebview().show("pop-in");
						setTimeout(function() {
							alert("此账号已在其他设备登录,请重新登录!");
							localStorage.clear();
							plus.runtime.restart();
						}, 30);
					}
				});
				// var userIds = JSON.parse(localStorage.getItem("userIds"));
				// // if (typeof userIds != undefined) {
				// // document.getElementById("userId").value = userIds;
				// $("#userId").val(userIds)
				// }
				window.addEventListener("select", function(e) {
					$("#userId").val(e.detail.userIdList);
					// 移除添加的option
					$("#waterId option[value != 0]").remove();
					// 将水表号添加到列表中
					$("#waterId").append("<option selected='selected' value='1'>" + e.detail.waterID + "</option>");
					// $("#waterId option[value = 0]").remove();
				})

				// 查询上一户
				mui(".btnQuiry").on("tap", "#previous_household", function() {
					var myStorage = JSON.parse(localStorage.getItem("users"));
					var glbToken = myStorage.glbToken;
					if (checkToken(glbToken).status == "ok") {
						mui.showLoading("正在查询中..", "div");
						var userId = $("#userId").val();

						// var waterId = document.getElementById("waterId");
						// var index = waterId.selectedIndex;
						// var waterIdText = waterId[index].text;
						var waterIdText = $("#waterId option:selected").text();

						if (waterIdText == "请选择水表号") {
							var waterIdList = getWaterIDList(userId, glbToken);
							if (waterIdList.length == 0) {
								mui.hideLoading();
								alert("请您检查用户号是否正确");
								// $("#waterId").append("<option value='0'>" + "请选择水表号" + "</option>");
							} else {
								// for (var i = 0; i < waterIdList.length; i++) {
								// 	$("#waterId").append("<option selected='selected'>" + waterIdList[i].WaterID + "</option>");
								// }
								// 有两个水表号的均以第一个为查询基础
								$("#waterId").append("<option selected='selected'>" + waterIdList[0].WaterID + "</option>");

								// $("#waterId option[value = 0]").remove();
								index = document.getElementById("waterId").selectedIndex;
								waterIdText = waterId[index].text;
								// var meterreader = glbToken.split("-")[0];
								if (getPriorUser(userId, waterIdText, glbToken).status == "ok") {
									var prioruserid = getPriorUser(userId, waterIdText, glbToken).prioruserid;
									var priorwaterid = getPriorUser(userId, waterIdText, glbToken).priorwaterid;
									$("#userId").val(prioruserid);
									$("#waterId option[value != 0]").remove();
									$("#waterId").append("<option selected='selected'>" + priorwaterid + "</option>");

									// 查询结果
									// 清空用水吨位的数据
									var waterTonnage = document.getElementById("waterTonnage");
									waterTonnage.innerText = " ";

									// 将用户号及水表号保存到临时input中
									$("#userId_sto").val(prioruserid);
									$("#waterId_sto").val(priorwaterid);
									setTimeout(function() {
										if (($("#userId_sto").val() && $("#waterId_sto").val()) != "") {
											mui.hideLoading();
										}
									}, 500);
									// 
									var userWaterData = getUseWaterData(prioruserid, priorwaterid, glbToken);
									if (userWaterData.status == "error") {
										if (userId == "") {
											mui.hideLoading();
											alert("用户号不能为空！");
										} else {
											mui.hideLoading();
											alert("无此用户");
										}
										// alert("无此用户");
									} else if (userWaterData.status == "tips") {
										var userName = document.getElementById("userName");
										userName.innerText = " ";
										var meterReadingDate = document.getElementById("meterReadingDate");
										meterReadingDate.innerText = " ";
										var lastMonthCode = document.getElementById("lastMonthCode");
										lastMonthCode.innerText = " ";
										var meterReading = document.getElementById("meterReading");
										meterReading.innerText = " ";
										var useraddress = document.getElementById("useraddress");
										useraddress.innerText = " ";
										var waterfactorid = document.getElementById('waterfactorid');
										waterfactorid.innerText = " ";
										$("#submit").text("保存");
										alert("本月抄表已提交处理！无需再次录入");
									} else {
										// 修改提交按钮的值
										if (userWaterData.isnew == 0) {

											var thisMonth = userWaterData.thismonthcode;
											// var estimateTonnage = $("#estimateTonnage").val();
											var pre = userWaterData.precheckcode;
											var after = userWaterData.aftercheckcode;
											var offSet = userWaterData.offset;
											var memo = userWaterData.memo;
											// 用水吨位计算
											var waterTonnage = document.getElementById("waterTonnage");
											var start_stop = thisMonth.toString() - userWaterData.lastmonthcode;
											var pre_after = pre.toString() - after.toString();
											waterTonnage.innerText = start_stop + pre_after;
											// 将已录入抄码数填充到本月抄码input中
											$("#thisMonth").val(thisMonth);
											$("#estimateTonnage").val(userWaterData.estimatetonnage);
											$("#pre").val(pre);
											$("#after").val(after);
											$("#offSet").val(offSet);
											$("#memo").val(memo);

											$("#submit").text("更新提交");
										} else if (userWaterData.isnew == 1) {
											$("#thisMonth").val("");
											$("#estimateTonnage").val(0);
											$("#pre").val(0);
											$("#after").val(0);
											$("#offSet").val(0);
											$("#memo").val('');
											$("#submit").text("新增提交");
										} else {
											$("#submit").text("提交");
										}
										var userName = document.getElementById("userName");
										userName.innerText = userWaterData.username;
										var meterReadingDate = document.getElementById("meterReadingDate");
										meterReadingDate.innerText = userWaterData.currentmonth;
										var lastMonthCode = document.getElementById("lastMonthCode");
										lastMonthCode.innerText = userWaterData.lastmonthcode;
										var meterReading = document.getElementById("meterReading");
										meterReading.innerText = userWaterData.meterreader;
										var useraddress = document.getElementById("useraddress");
										useraddress.innerText = userWaterData.useraddress;
										var waterfactorid = document.getElementById('waterfactorid');
										waterfactorid.innerText = userWaterData.waterfactorid;
									}
								} else {
									setTimeout(function() {
										// if (($("#userId_sto").val() && $("#waterId_sto").val()) != "") {
										mui.hideLoading();
										alert("该用户已经是第一个了！");
										// }
									}, 500);
								}
							}
						} else {
							// var meterreader = glbToken.split("-")[0];
							// alert(meterreader)
							if (getPriorUser(userId, waterIdText, glbToken).status == "ok") {
								var prioruserid = getPriorUser(userId, waterIdText, glbToken).prioruserid;
								var priorwaterid = getPriorUser(userId, waterIdText, glbToken).priorwaterid;
								$("#userId").val(prioruserid);
								$("#waterId option[value != 0]").remove();
								$("#waterId").append("<option selected='selected'>" + priorwaterid + "</option>");

								// 查询结果
								// 清空用水吨位的数据
								var waterTonnage = document.getElementById("waterTonnage");
								waterTonnage.innerText = " ";

								// 将用户号及水表号保存到临时input中
								$("#userId_sto").val(prioruserid);
								$("#waterId_sto").val(priorwaterid);
								// 关闭loading
								setTimeout(function() {
									if (($("#userId_sto").val() && $("#waterId_sto").val()) != "") {
										mui.hideLoading();
									}
								}, 500);
								// 
								var userWaterData = getUseWaterData(prioruserid, priorwaterid, glbToken);
								if (userWaterData.status == "error") {
									if (userId == "") {
										mui.hideLoading();
										alert("用户号不能为空！");
									} else {
										mui.hideLoading();
										alert("无此用户");
									}
									// alert("无此用户");
								} else if (userWaterData.status == "tips") {
									var userName = document.getElementById("userName");
									userName.innerText = " ";
									var meterReadingDate = document.getElementById("meterReadingDate");
									meterReadingDate.innerText = " ";
									var lastMonthCode = document.getElementById("lastMonthCode");
									lastMonthCode.innerText = " ";
									var meterReading = document.getElementById("meterReading");
									meterReading.innerText = " ";
									var useraddress = document.getElementById("useraddress");
									useraddress.innerText = " ";
									var waterfactorid = document.getElementById('waterfactorid');
									waterfactorid.innerText = " ";
									$("#submit").text("保存");
									alert("本月抄表已提交处理！无需再次录入");
								} else {
									// 修改提交按钮的值
									if (userWaterData.isnew == 0) {

										var thisMonth = userWaterData.thismonthcode;
										// var estimateTonnage = $("#estimateTonnage").val();
										var pre = userWaterData.precheckcode;
										var after = userWaterData.aftercheckcode;
										var offSet = userWaterData.offset;
										var memo = userWaterData.memo;
										// 用水吨位计算
										var waterTonnage = document.getElementById("waterTonnage");
										var start_stop = thisMonth.toString() - userWaterData.lastmonthcode;
										var pre_after = pre.toString() - after.toString();
										waterTonnage.innerText = start_stop + pre_after;
										// 将已录入抄码数填充到本月抄码input中
										$("#thisMonth").val(thisMonth);
										$("#estimateTonnage").val(userWaterData.estimatetonnage);
										$("#pre").val(pre);
										$("#after").val(after);
										$("#offSet").val(offSet);
										$("#memo").val(memo);

										$("#submit").text("更新提交");
									} else if (userWaterData.isnew == 1) {
										$("#thisMonth").val("");
										$("#estimateTonnage").val(0);
										$("#pre").val(0);
										$("#after").val(0);
										$("#offSet").val(0);
										$("#memo").val('');
										$("#submit").text("新增提交");
									} else {
										$("#submit").text("提交");
									}
									var userName = document.getElementById("userName");
									userName.innerText = userWaterData.username;
									var meterReadingDate = document.getElementById("meterReadingDate");
									meterReadingDate.innerText = userWaterData.currentmonth;
									var lastMonthCode = document.getElementById("lastMonthCode");
									lastMonthCode.innerText = userWaterData.lastmonthcode;
									var meterReading = document.getElementById("meterReading");
									meterReading.innerText = userWaterData.meterreader;
									var useraddress = document.getElementById("useraddress");
									useraddress.innerText = userWaterData.useraddress;
									var waterfactorid = document.getElementById('waterfactorid');
									waterfactorid.innerText = userWaterData.waterfactorid;
								}
							} else {
								setTimeout(function() {
									// if (($("#userId_sto").val() && $("#waterId_sto").val()) != "") {
									mui.hideLoading();
									alert("该用户已经是第一个了！");
									// }
								}, 500);
							}
						}
					} else {
						app.setState({});
						plus.webview.getLaunchWebview().show("pop-in");
						setTimeout(function() {
							alert("此账号已在其他设备登录,请重新登录!");
							localStorage.clear();
							plus.runtime.restart();
						}, 30);
					}
				})

				// 查询下一户
				mui(".btnQuiry").on("tap", "#next_household", function() {
					var myStorage = JSON.parse(localStorage.getItem("users"));
					var glbToken = myStorage.glbToken;
					if (checkToken(glbToken).status == "ok") {
						mui.showLoading("正在查询中..", "div");
						var userId = $("#userId").val();

						// var waterId = document.getElementById("waterId");
						// var index = waterId.selectedIndex;
						// var waterIdText = waterId[index].text;
						var waterIdText = $("#waterId option:selected").text();
						if (waterIdText == "请选择水表号") {
							var waterIdList = getWaterIDList(userId, glbToken);
							if (waterIdList.length == 0) {
								mui.hideLoading();
								alert("请您检查用户号是否正确");
								// $("#waterId").append("<option value='0'>" + "请选择水表号" + "</option>");
							} else {
								// for (var i = 0; i < waterIdList.length; i++) {
								// 	$("#waterId").append("<option selected='selected'>" + waterIdList[i].WaterID + "</option>");
								// }

								// 有两个水表号的均以第一个为查询基础
								$("#waterId").append("<option selected='selected'>" + waterIdList[0].WaterID + "</option>");

								// $("#waterId option[value = 0]").remove();
								index = document.getElementById("waterId").selectedIndex;
								waterIdText = waterId[index].text;
								// var meterreader = glbToken.split("-")[0];
								if (getNextUser(userId, waterIdText, glbToken).status == "ok") {
									var nextuserid = getNextUser(userId, waterIdText, glbToken).nextuserid;
									var nextwaterid = getNextUser(userId, waterIdText, glbToken).nextwaterid;
									$("#userId").val(nextuserid);
									$("#waterId option[value != 0]").remove();
									$("#waterId").append("<option selected='selected'>" + nextwaterid + "</option>");

									// 查询结果
									// 清空用水吨位的数据
									var waterTonnage = document.getElementById("waterTonnage");
									waterTonnage.innerText = " ";

									// 将用户号及水表号保存到临时input中
									$("#userId_sto").val(nextuserid);
									$("#waterId_sto").val(nextwaterid);
									// 关闭loading
									setTimeout(function() {
										if (($("#userId_sto").val() && $("#waterId_sto").val()) != "") {
											mui.hideLoading();
										}
									}, 500);
									// 
									var userWaterData = getUseWaterData(nextuserid, nextwaterid, glbToken);
									if (userWaterData.status == "error") {
										if (userId == "") {
											mui.hideLoading();
											alert("用户号不能为空！");
										} else {
											mui.hideLoading();
											alert("无此用户");
										}
										// alert("无此用户");
									} else if (userWaterData.status == "tips") {
										var userName = document.getElementById("userName");
										userName.innerText = " ";
										var meterReadingDate = document.getElementById("meterReadingDate");
										meterReadingDate.innerText = " ";
										var lastMonthCode = document.getElementById("lastMonthCode");
										lastMonthCode.innerText = " ";
										var meterReading = document.getElementById("meterReading");
										meterReading.innerText = " ";
										var useraddress = document.getElementById("useraddress");
										useraddress.innerText = " ";
										var waterfactorid = document.getElementById('waterfactorid');
										waterfactorid.innerText = " ";
										$("#submit").text("保存");
										alert("本月抄表已提交处理！无需再次录入");
									} else {
										// 修改提交按钮的值
										if (userWaterData.isnew == 0) {

											var thisMonth = userWaterData.thismonthcode;
											// var estimateTonnage = $("#estimateTonnage").val();
											var pre = userWaterData.precheckcode;
											var after = userWaterData.aftercheckcode;
											var offSet = userWaterData.offset;
											var memo = userWaterData.memo;
											// 用水吨位计算
											var waterTonnage = document.getElementById("waterTonnage");
											var start_stop = thisMonth.toString() - userWaterData.lastmonthcode;
											var pre_after = pre.toString() - after.toString();
											waterTonnage.innerText = start_stop + pre_after;
											// 将已录入抄码数填充到本月抄码input中
											$("#thisMonth").val(thisMonth);
											$("#estimateTonnage").val(userWaterData.estimatetonnage);
											$("#pre").val(pre);
											$("#after").val(after);
											$("#offSet").val(offSet);
											$("#memo").val(memo);

											$("#submit").text("更新提交");
										} else if (userWaterData.isnew == 1) {
											$("#thisMonth").val("");
											$("#estimateTonnage").val(0);
											$("#pre").val(0);
											$("#after").val(0);
											$("#offSet").val(0);
											$("#memo").val('');
											$("#submit").text("新增提交");
										} else {
											$("#submit").text("提交");
										}
										var userName = document.getElementById("userName");
										userName.innerText = userWaterData.username;
										var meterReadingDate = document.getElementById("meterReadingDate");
										meterReadingDate.innerText = userWaterData.currentmonth;
										var lastMonthCode = document.getElementById("lastMonthCode");
										lastMonthCode.innerText = userWaterData.lastmonthcode;
										var meterReading = document.getElementById("meterReading");
										meterReading.innerText = userWaterData.meterreader;
										var useraddress = document.getElementById("useraddress");
										useraddress.innerText = userWaterData.useraddress;
										var waterfactorid = document.getElementById('waterfactorid');
										waterfactorid.innerText = userWaterData.waterfactorid;
									}
								} else {
									setTimeout(function() {
										// if (($("#userId_sto").val() && $("#waterId_sto").val()) != "") {
										mui.hideLoading();
										alert("该用户已经是最后一个了！");
									}, 500);

								}
							}
						} else {
							// var meterreader = glbToken.split("-")[0];
							// alert(meterreader)
							if (getNextUser(userId, waterIdText, glbToken).status == "ok") {
								var nextuserid = getNextUser(userId, waterIdText, glbToken).nextuserid;
								var nextwaterid = getNextUser(userId, waterIdText, glbToken).nextwaterid;
								$("#userId").val(nextuserid);
								$("#waterId option[value != 0]").remove();
								$("#waterId").append("<option selected='selected'>" + nextwaterid + "</option>");

								// 查询结果
								// 清空用水吨位的数据
								var waterTonnage = document.getElementById("waterTonnage");
								waterTonnage.innerText = " ";

								// 将用户号及水表号保存到临时input中
								$("#userId_sto").val(nextuserid);
								$("#waterId_sto").val(nextwaterid);
								// 关闭loading
								setTimeout(function() {
									if (($("#userId_sto").val() && $("#waterId_sto").val()) != "") {
										mui.hideLoading();
									}
								}, 500);
								// 
								var userWaterData = getUseWaterData(nextuserid, nextwaterid, glbToken);
								if (userWaterData.status == "error") {
									if (userId == "") {
										mui.hideLoading();
										alert("用户号不能为空");
									} else {
										mui.hideLoading();
										alert("无此用户");
									}
									// alert("无此用户");
								} else if (userWaterData.status == "tips") {
									var userName = document.getElementById("userName");
									userName.innerText = " ";
									var meterReadingDate = document.getElementById("meterReadingDate");
									meterReadingDate.innerText = " ";
									var lastMonthCode = document.getElementById("lastMonthCode");
									lastMonthCode.innerText = " ";
									var meterReading = document.getElementById("meterReading");
									meterReading.innerText = " ";
									var useraddress = document.getElementById("useraddress");
									useraddress.innerText = " ";
									var waterfactorid = document.getElementById('waterfactorid');
									waterfactorid.innerText = " ";
									$("#submit").text("保存");
									alert("本月抄表已提交处理！无需再次录入");
								} else {
									// 修改提交按钮的值
									if (userWaterData.isnew == 0) {

										var thisMonth = userWaterData.thismonthcode;
										// var estimateTonnage = $("#estimateTonnage").val();
										var pre = userWaterData.precheckcode;
										var after = userWaterData.aftercheckcode;
										var offSet = userWaterData.offset;
										var memo = userWaterData.memo;
										// 用水吨位计算
										var waterTonnage = document.getElementById("waterTonnage");
										var start_stop = thisMonth.toString() - userWaterData.lastmonthcode;
										var pre_after = pre.toString() - after.toString();
										waterTonnage.innerText = start_stop + pre_after;
										// 将已录入抄码数填充到本月抄码input中
										$("#thisMonth").val(thisMonth);
										$("#estimateTonnage").val(userWaterData.estimatetonnage);
										$("#pre").val(pre);
										$("#after").val(after);
										$("#offSet").val(offSet);
										$("#memo").val(memo);

										$("#submit").text("更新提交");
									} else if (userWaterData.isnew == 1) {
										$("#thisMonth").val("");
										$("#estimateTonnage").val(0);
										$("#pre").val(0);
										$("#after").val(0);
										$("#offSet").val(0);
										$("#memo").val('');
										$("#submit").text("新增提交");
									} else {
										$("#submit").text("提交");
									}
									var userName = document.getElementById("userName");
									userName.innerText = userWaterData.username;
									var meterReadingDate = document.getElementById("meterReadingDate");
									meterReadingDate.innerText = userWaterData.currentmonth;
									var lastMonthCode = document.getElementById("lastMonthCode");
									lastMonthCode.innerText = userWaterData.lastmonthcode;
									var meterReading = document.getElementById("meterReading");
									meterReading.innerText = userWaterData.meterreader;
									var useraddress = document.getElementById("useraddress");
									useraddress.innerText = userWaterData.useraddress;
									var waterfactorid = document.getElementById('waterfactorid');
									waterfactorid.innerText = userWaterData.waterfactorid;
								}
							} else {
								setTimeout(function() {
									// if (($("#userId_sto").val() && $("#waterId_sto").val()) != "") {
									mui.hideLoading();
									alert("该用户已经是最后一个了！");
									// }
								}, 500);

							}
						}
					} else {
						app.setState({});
						plus.webview.getLaunchWebview().show("pop-in");
						setTimeout(function() {
							alert("此账号已在其他设备登录,请重新登录!");
							localStorage.clear();
							plus.runtime.restart();
						}, 30);
					}
				})

				// 查询用户信息
				$("#quiryData").click(function() {
					var myStorage = JSON.parse(localStorage.getItem("users"));
					var glbToken = myStorage.glbToken;

					if (checkToken(glbToken).status == "ok") {
						mui.showLoading("正在查询中..", "div");
						// 清空用水吨位的数据
						var waterTonnage = document.getElementById("waterTonnage");
						waterTonnage.innerText = " ";

						// 清空临时input中的数据
						$("#userId_sto").val("");
						$("#waterId_sto").val("");

						var userId = $("#userId").val();
						var waterId = document.getElementById("waterId");
						var index = waterId.selectedIndex;
						var waterIdText = waterId[index].text;
						if (waterIdText == "请选择水表号") {
							waterIdText = "";
							var userWaterData = getUseWaterData(userId, waterIdText, glbToken);
							// 将用户号及水表号保存到临时input中
							$("#userId_sto").val(userId);
							$("#waterId_sto").val(userWaterData.waterid);
							setTimeout(function() {
								if (($("#userId_sto").val() && $("#waterId_sto").val()) != "") {
									mui.hideLoading();
								}
							}, 400);

							// var userWaterData = getUseWaterData(userId, waterIdText, glbToken);
							if (userWaterData.status == "error") {
								if (userId == "") {
									mui.hideLoading();
									alert("用户号不能为空！");
								} else {
									mui.hideLoading();
									alert("无此用户");
								}

							} else if (userWaterData.status == "tips") {
								mui.hideLoading();
								var userName = document.getElementById("userName");
								userName.innerText = " ";
								var meterReadingDate = document.getElementById("meterReadingDate");
								meterReadingDate.innerText = " ";
								var lastMonthCode = document.getElementById("lastMonthCode");
								lastMonthCode.innerText = " ";
								var meterReading = document.getElementById("meterReading");
								meterReading.innerText = " ";
								var useraddress = document.getElementById("useraddress");
								useraddress.innerText = " ";
								var waterfactorid = document.getElementById('waterfactorid');
								waterfactorid.innerText = " ";
								$("#submit").text("保存");
								alert("本月抄表已提交处理！无需再次录入");
							} else {
								// 修改提交按钮的值
								if (userWaterData.isnew == 0) {
									var thisMonth = userWaterData.thismonthcode;
									// var estimateTonnage = $("#estimateTonnage").val();
									var pre = userWaterData.precheckcode;
									var after = userWaterData.aftercheckcode;
									var offSet = userWaterData.offset;
									var memo = userWaterData.memo;
									// 用水吨位计算
									var waterTonnage = document.getElementById("waterTonnage");
									var start_stop = thisMonth.toString() - userWaterData.lastmonthcode;
									var pre_after = pre.toString() - after.toString();
									waterTonnage.innerText = start_stop + pre_after;
									// 将已录入抄码数填充到本月抄码input中
									$("#thisMonth").val(thisMonth);
									$("#estimateTonnage").val(userWaterData.estimatetonnage);
									$("#pre").val(pre);
									$("#after").val(after);
									$("#offSet").val(offSet);
									$("#memo").val(memo);

									$("#submit").text("更新");
								} else if (userWaterData.isnew == 1) {
									$("#thisMonth").val("");
									$("#estimateTonnage").val(0);
									$("#pre").val(0);
									$("#after").val(0);
									$("#offSet").val(0);
									$("#memo").val('');
									$("#submit").text("新增");
								} else {
									$("#submit").text("保存");
								}
								var userName = document.getElementById("userName");
								userName.innerText = userWaterData.username;
								var meterReadingDate = document.getElementById("meterReadingDate");
								meterReadingDate.innerText = userWaterData.currentmonth;
								var lastMonthCode = document.getElementById("lastMonthCode");
								lastMonthCode.innerText = userWaterData.lastmonthcode;
								var meterReading = document.getElementById("meterReading");
								meterReading.innerText = userWaterData.meterreader;
								var useraddress = document.getElementById("useraddress");
								useraddress.innerText = userWaterData.useraddress;
								var waterfactorid = document.getElementById('waterfactorid');
								waterfactorid.innerText = userWaterData.waterfactorid;
							}
						} else {
							// 将用户号及水表号保存到临时input中
							$("#userId_sto").val(userId);
							$("#waterId_sto").val(waterIdText);
							setTimeout(function() {
								if (($("#userId_sto").val() && $("#waterId_sto").val()) != "") {
									mui.hideLoading();
								}
							}, 400);

							var userWaterData = getUseWaterData(userId, waterIdText, glbToken);
							if (userWaterData.status == "error") {
								if (userId == "") {
									mui.hideLoading();
									alert("用户号不能为空");
								} else if (userWaterData.msg == '用户号与水表号不匹配！') {
									mui.hideLoading();
									alert("用户号与水表号不匹配！");
								} else {
									mui.hideLoading();
									alert("无此用户");
								}
							} else if (userWaterData.status == "tips") {
								mui.hideLoading();
								var userName = document.getElementById("userName");
								userName.innerText = " ";
								var meterReadingDate = document.getElementById("meterReadingDate");
								meterReadingDate.innerText = " ";
								var lastMonthCode = document.getElementById("lastMonthCode");
								lastMonthCode.innerText = " ";
								var meterReading = document.getElementById("meterReading");
								meterReading.innerText = " ";
								var useraddress = document.getElementById("useraddress");
								useraddress.innerText = " ";
								var waterfactorid = document.getElementById('waterfactorid');
								waterfactorid.innerText = " ";
								$("#submit").text("保存");
								alert("本月抄表已提交处理！无需再次录入");
							} else {
								// 修改提交按钮的值
								if (userWaterData.isnew == 0) {
									var thisMonth = userWaterData.thismonthcode;
									// var estimateTonnage = $("#estimateTonnage").val();
									var pre = userWaterData.precheckcode;
									var after = userWaterData.aftercheckcode;
									var offSet = userWaterData.offset;
									var memo = userWaterData.memo;
									// 用水吨位计算
									var waterTonnage = document.getElementById("waterTonnage");
									var start_stop = thisMonth.toString() - userWaterData.lastmonthcode;
									var pre_after = pre.toString() - after.toString();
									waterTonnage.innerText = start_stop + pre_after;
									// 将已录入抄码数填充到本月抄码input中
									$("#thisMonth").val(thisMonth);
									$("#estimateTonnage").val(userWaterData.estimatetonnage);
									$("#pre").val(pre);
									$("#after").val(after);
									$("#offSet").val(offSet);
									$("#memo").val(memo);
									// document.getElementById("currentMeterReading_result").innerText = thisMonth;
									$("#submit").text("更新");
								} else if (userWaterData.isnew == 1) {
									$("#thisMonth").val("");
									$("#estimateTonnage").val(0);
									$("#pre").val(0);
									$("#after").val(0);
									$("#offSet").val(0);
									$("#memo").val('');
									$("#submit").text("新增");
								} else {
									$("#submit").text("保存");
								}
								// 显示查询结果
								var userName = document.getElementById("userName");
								userName.innerText = userWaterData.username;
								var meterReadingDate = document.getElementById("meterReadingDate");
								meterReadingDate.innerText = userWaterData.currentmonth;
								var lastMonthCode = document.getElementById("lastMonthCode");
								lastMonthCode.innerText = userWaterData.lastmonthcode;
								var meterReading = document.getElementById("meterReading");
								meterReading.innerText = userWaterData.meterreader;
								var useraddress = document.getElementById("useraddress");
								useraddress.innerText = userWaterData.useraddress;
								var waterfactorid = document.getElementById('waterfactorid');
								waterfactorid.innerText = userWaterData.waterfactorid;
							}
						}
					} else {
						app.setState({});
						plus.webview.getLaunchWebview().show("pop-in");
						setTimeout(function() {
							alert("此账号已在其他设备登录,请重新登录!");
							localStorage.clear();
							plus.runtime.restart();
						}, 30)
					}
				})

				// 提交抄表数据
				$("#submit").click(function() {
					var myStorage = JSON.parse(localStorage.getItem("users"));
					var glbToken = myStorage.glbToken;
					var staffid = myStorage.staffid;
					
					// 防止重复点击提交按钮
					$("#submit").attr("disabled", true);
					
					if (checkToken(glbToken).status == "ok") {
						// 取出临时input中的用户号及水表号
						var userId = $("#userId_sto").val();
						var waterIdText = $("#waterId_sto").val();

						var userWaterData = getUseWaterData(userId, waterIdText, glbToken);
						var lastmonthtonnages = userWaterData.lastmonthtonnage;

						var thisMonth = $("#thisMonth").val();
						var estimateTonnage = $("#estimateTonnage").val();
						var pre = $("#pre").val();
						var after = $("#after").val();
						var offSet = $("#offSet").val();
						var memo = $("#memo").val();
						// 用水吨位计算
						var waterTonnage = document.getElementById("waterTonnage");
						var start_stop = thisMonth - Number(userWaterData.lastmonthcode);
						var pre_after = pre - after;

						var waterTonnage_value = start_stop + pre_after;

						// 数据提交
						if (userWaterData.isnew == 0) {
							if (waterTonnage_value >= 0 && thisMonth != "") {
								// 获取抄表位置信息
								plus.nativeUI.showWaiting("正在定位...", {
									padlock: false
								});
								if (plus.os.name == "Android") {
									var context = plus.android.importClass("android.content.Context");
									var locationManager = plus.android.importClass("android.location.LocationManager");
									var main = plus.android.runtimeMainActivity();
									var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
									androidIsOpen = mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER);
									if (androidIsOpen) {
										plus.geolocation.getCurrentPosition(function(p) {
											var latitude = p.coords.latitude;
											var longitude = p.coords.longitude;
											var altitude = p.coords.altitude;
											var geolocationInfo = saveCoord(staffid, userId, longitude, latitude, altitude, glbToken);
											if (geolocationInfo.status == 'ok') {
												// 更新操作
												var updateData = UpdateUseWaterData(userId, userWaterData.waterid, userWaterData.currentmonth,
													userWaterData.lastmonthcode,
													thisMonth, pre, after, estimateTonnage, offSet, glbToken, memo);
												// alert(updateData.msg)
												if (updateData.status == "ok") {
													setTimeout(function() {
														// mui.hideLoading();
														mui.toast('更新成功',{ duration:'short', type:'div' });
														if (start_stop + pre_after >= 0) {
															waterTonnage.innerText = start_stop + pre_after;
														}
														
														// 更新成功后直接查找下一户
														var userId = $("#userId").val();
														
														// var waterId = document.getElementById("waterId");
														// var index = waterId.selectedIndex;
														// var waterIdText = waterId[index].text;
														var waterIdText = $("#waterId option:selected").text();
														if (waterIdText == "请选择水表号") {
															var waterIdList = getWaterIDList(userId, glbToken);
															if (waterIdList.length == 0) {
																// mui.hideLoading();
																alert("请您检查用户号是否正确");
																// $("#waterId").append("<option value='0'>" + "请选择水表号" + "</option>");
															} else {
																// for (var i = 0; i < waterIdList.length; i++) {
																// 	$("#waterId").append("<option selected='selected'>" + waterIdList[i].WaterID + "</option>");
																// }
														
																// 有两个水表号的均以第一个为查询基础
																$("#waterId").append("<option selected='selected'>" + waterIdList[0].WaterID + "</option>");
														
																// $("#waterId option[value = 0]").remove();
																index = document.getElementById("waterId").selectedIndex;
																waterIdText = waterId[index].text;
																// var meterreader = glbToken.split("-")[0];
																if (getNextUser(userId, waterIdText, glbToken).status == "ok") {
																	var nextuserid = getNextUser(userId, waterIdText, glbToken).nextuserid;
																	var nextwaterid = getNextUser(userId, waterIdText, glbToken).nextwaterid;
																	$("#userId").val(nextuserid);
																	$("#waterId option[value != 0]").remove();
																	$("#waterId").append("<option selected='selected'>" + nextwaterid + "</option>");
														
																	// 查询结果
																	// 清空用水吨位的数据
																	var waterTonnage = document.getElementById("waterTonnage");
																	waterTonnage.innerText = " ";
														
																	// 将用户号及水表号保存到临时input中
																	$("#userId_sto").val(nextuserid);
																	$("#waterId_sto").val(nextwaterid);
																	// 关闭loading
																	setTimeout(function() {
																		if (($("#userId_sto").val() && $("#waterId_sto").val()) != "") {
																			mui.hideLoading();
																		}
																	}, 500);
																	// 
																	var userWaterData = getUseWaterData(nextuserid, nextwaterid, glbToken);
																	if (userWaterData.status == "error") {
																		if (userId == "") {
																			mui.hideLoading();
																			alert("用户号不能为空！");
																		} else {
																			mui.hideLoading();
																			alert("无此用户");
																		}
																		// alert("无此用户");
																	} else if (userWaterData.status == "tips") {
																		var userName = document.getElementById("userName");
																		userName.innerText = " ";
																		var meterReadingDate = document.getElementById("meterReadingDate");
																		meterReadingDate.innerText = " ";
																		var lastMonthCode = document.getElementById("lastMonthCode");
																		lastMonthCode.innerText = " ";
																		var meterReading = document.getElementById("meterReading");
																		meterReading.innerText = " ";
																		var useraddress = document.getElementById("useraddress");
																		useraddress.innerText = " ";
																		var waterfactorid = document.getElementById('waterfactorid');
																		waterfactorid.innerText = " ";
																		$("#submit").text("保存");
																		alert("本月抄表已提交处理！无需再次录入");
																	} else {
																		// 修改提交按钮的值
																		if (userWaterData.isnew == 0) {
														
																			var thisMonth = userWaterData.thismonthcode;
																			// var estimateTonnage = $("#estimateTonnage").val();
																			var pre = userWaterData.precheckcode;
																			var after = userWaterData.aftercheckcode;
																			var offSet = userWaterData.offset;
																			var memo = userWaterData.memo;
																			// 用水吨位计算
																			var waterTonnage = document.getElementById("waterTonnage");
																			var start_stop = thisMonth.toString() - userWaterData.lastmonthcode;
																			var pre_after = pre.toString() - after.toString();
																			waterTonnage.innerText = start_stop + pre_after;
																			// 将已录入抄码数填充到本月抄码input中
																			$("#thisMonth").val(thisMonth);
																			$("#estimateTonnage").val(userWaterData.estimatetonnage);
																			$("#pre").val(pre);
																			$("#after").val(after);
																			$("#offSet").val(offSet);
																			$("#memo").val(memo);
														
																			$("#submit").text("更新提交");
																		} else if (userWaterData.isnew == 1) {
																			$("#thisMonth").val("");
																			$("#estimateTonnage").val(0);
																			$("#pre").val(0);
																			$("#after").val(0);
																			$("#offSet").val(0);
																			$("#submit").text("新增提交");
																		} else {
																			$("#submit").text("提交");
																		}
																		var userName = document.getElementById("userName");
																		userName.innerText = userWaterData.username;
																		var meterReadingDate = document.getElementById("meterReadingDate");
																		meterReadingDate.innerText = userWaterData.currentmonth;
																		var lastMonthCode = document.getElementById("lastMonthCode");
																		lastMonthCode.innerText = userWaterData.lastmonthcode;
																		var meterReading = document.getElementById("meterReading");
																		meterReading.innerText = userWaterData.meterreader;
																		var useraddress = document.getElementById("useraddress");
																		useraddress.innerText = userWaterData.useraddress;
																		var waterfactorid = document.getElementById('waterfactorid');
																		waterfactorid.innerText = userWaterData.waterfactorid;
																	}
																} else {
																	setTimeout(function() {
																		// if (($("#userId_sto").val() && $("#waterId_sto").val()) != "") {
																		mui.hideLoading();
																		alert("该用户已经是最后一个了！");
																	}, 500);
														
																}
															}
														} else {
															// var meterreader = glbToken.split("-")[0];
															// alert(meterreader)
															if (getNextUser(userId, waterIdText, glbToken).status == "ok") {
																var nextuserid = getNextUser(userId, waterIdText, glbToken).nextuserid;
																var nextwaterid = getNextUser(userId, waterIdText, glbToken).nextwaterid;
																$("#userId").val(nextuserid);
																$("#waterId option[value != 0]").remove();
																$("#waterId").append("<option selected='selected'>" + nextwaterid + "</option>");
														
																// 查询结果
																// 清空用水吨位的数据
																var waterTonnage = document.getElementById("waterTonnage");
																waterTonnage.innerText = " ";
														
																// 将用户号及水表号保存到临时input中
																$("#userId_sto").val(nextuserid);
																$("#waterId_sto").val(nextwaterid);
																// 关闭loading
																setTimeout(function() {
																	if (($("#userId_sto").val() && $("#waterId_sto").val()) != "") {
																		mui.hideLoading();
																	}
																}, 500);
																// 
																var userWaterData = getUseWaterData(nextuserid, nextwaterid, glbToken);
																if (userWaterData.status == "error") {
																	if (userId == "") {
																		mui.hideLoading();
																		alert("用户号不能为空");
																	} else {
																		mui.hideLoading();
																		alert("无此用户");
																	}
																	// alert("无此用户");
																} else if (userWaterData.status == "tips") {
																	var userName = document.getElementById("userName");
																	userName.innerText = " ";
																	var meterReadingDate = document.getElementById("meterReadingDate");
																	meterReadingDate.innerText = " ";
																	var lastMonthCode = document.getElementById("lastMonthCode");
																	lastMonthCode.innerText = " ";
																	var meterReading = document.getElementById("meterReading");
																	meterReading.innerText = " ";
																	var useraddress = document.getElementById("useraddress");
																	useraddress.innerText = " ";
																	var waterfactorid = document.getElementById('waterfactorid');
																	waterfactorid.innerText = " ";
																	$("#submit").text("保存");
																	alert("本月抄表已提交处理！无需再次录入");
																} else {
																	// 修改提交按钮的值
																	if (userWaterData.isnew == 0) {
														
																		var thisMonth = userWaterData.thismonthcode;
																		// var estimateTonnage = $("#estimateTonnage").val();
																		var pre = userWaterData.precheckcode;
																		var after = userWaterData.aftercheckcode;
																		var offSet = userWaterData.offset;
																		var memo = userWaterData.memo;
																		// 用水吨位计算
																		var waterTonnage = document.getElementById("waterTonnage");
																		var start_stop = thisMonth.toString() - userWaterData.lastmonthcode;
																		var pre_after = pre.toString() - after.toString();
																		waterTonnage.innerText = start_stop + pre_after;
																		// 将已录入抄码数填充到本月抄码input中
																		$("#thisMonth").val(thisMonth);
																		$("#estimateTonnage").val(userWaterData.estimatetonnage);
																		$("#pre").val(pre);
																		$("#after").val(after);
																		$("#offSet").val(offSet);
																		$("#memo").val(memo);
														
																		$("#submit").text("更新提交");
																	} else if (userWaterData.isnew == 1) {
																		$("#thisMonth").val("");
																		$("#estimateTonnage").val(0);
																		$("#pre").val(0);
																		$("#after").val(0);
																		$("#offSet").val(0);
																		$("#memo").val('');
																		$("#submit").text("新增提交");
																	} else {
																		$("#submit").text("提交");
																	}
																	var userName = document.getElementById("userName");
																	userName.innerText = userWaterData.username;
																	var meterReadingDate = document.getElementById("meterReadingDate");
																	meterReadingDate.innerText = userWaterData.currentmonth;
																	var lastMonthCode = document.getElementById("lastMonthCode");
																	lastMonthCode.innerText = userWaterData.lastmonthcode;
																	var meterReading = document.getElementById("meterReading");
																	meterReading.innerText = userWaterData.meterreader;
																	var useraddress = document.getElementById("useraddress");
																	useraddress.innerText = userWaterData.useraddress;
																	var waterfactorid = document.getElementById('waterfactorid');
																	waterfactorid.innerText = userWaterData.waterfactorid;
																}
															} else {
																setTimeout(function() {
																	// if (($("#userId_sto").val() && $("#waterId_sto").val()) != "") {
																	mui.hideLoading();
																	alert("该用户已经是最后一个了！");
																	// }
																}, 500);
														
															}
														}
														
													}, 300);
													$("#thisMonth").val("");
													$("#estimateTonnage").val(0);
													$("#pre").val(0);
													$("#after").val(0);
													$("#offSet").val(0);
													$("#memo").val('');
												} else if (updateData.msg == "不能修改已提交抄表！") {
													alert("不能修改已提交抄表!");
												} else {
													alert("更新失败");
												}
											} else {
												plus.nativeUI.alert('位置信息保存失败')
												return
											}
											plus.nativeUI.closeWaiting();
										}, function(e) {
											alert('Geolocation error: ' + e.message)
										}, {
											provider: 'baidu'
										});
										plus.nativeUI.closeWaiting()
									} else {
										mui.toast("请先开启位置服务");
										plus.nativeUI.closeWaiting()
										// 防止重复点击提交按钮移除事件
										$("#submit").attr("disabled", false);
										mui.hideLoading();
										return
									}
								}
							} else {
								alert("本月抄码不能为空且必须大于本月起码");
							}
						} else if (userWaterData.isnew == 1) {
							if (waterTonnage_value >= 0 && thisMonth != "") {
								// var flag = false;
								// // 根据用水吨位是否大于上月的5倍判断是否提示
								if (lastmonthtonnages > 0 && (waterTonnage_value > 5 * lastmonthtonnages)) {
									var btnArray = ['是', '否'];
									mui.confirm('请核对本月抄码是否正确！', '提示', btnArray, function(e) {
										if (e.index == 0) {
											// 获取抄表位置信息
											plus.nativeUI.showWaiting("正在定位...", {
												padlock: false
											});
											if (plus.os.name == "Android") {
												var context = plus.android.importClass("android.content.Context");
												var locationManager = plus.android.importClass("android.location.LocationManager");
												var main = plus.android.runtimeMainActivity();
												var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
												androidIsOpen = mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER);
												if (androidIsOpen) {
													plus.geolocation.getCurrentPosition(function(p) {
														var latitude = p.coords.latitude;
														var longitude = p.coords.longitude;
														var altitude = p.coords.altitude;
														var geolocationInfo = saveCoord(staffid, userId, longitude, latitude, altitude, glbToken);
														if (geolocationInfo.status == 'ok') {
															// 插入操作
															var addData = AddUseWaterData(userId, waterIdText, userWaterData.currentmonth, userWaterData.lastmonthcode,
																thisMonth, pre, after, estimateTonnage, offSet, glbToken, memo);
															if (addData.status == "ok") {
																setTimeout(function() {
																	// mui.hideLoading();
																	mui.toast('新增成功',{ duration:'short', type:'div' });
																	if (start_stop + pre_after >= 0) {
																		waterTonnage.innerText = start_stop + pre_after;
																	}
																	
																	// 新增成功后直接查找下一户
																	var userId = $("#userId").val();
																	
																	// var waterId = document.getElementById("waterId");
																	// var index = waterId.selectedIndex;
																	// var waterIdText = waterId[index].text;
																	var waterIdText = $("#waterId option:selected").text();
																	if (waterIdText == "请选择水表号") {
																		var waterIdList = getWaterIDList(userId, glbToken);
																		if (waterIdList.length == 0) {
																			// mui.hideLoading();
																			alert("请您检查用户号是否正确");
																			// $("#waterId").append("<option value='0'>" + "请选择水表号" + "</option>");
																		} else {
																			// for (var i = 0; i < waterIdList.length; i++) {
																			// 	$("#waterId").append("<option selected='selected'>" + waterIdList[i].WaterID + "</option>");
																			// }
																	
																			// 有两个水表号的均以第一个为查询基础
																			$("#waterId").append("<option selected='selected'>" + waterIdList[0].WaterID + "</option>");
																	
																			// $("#waterId option[value = 0]").remove();
																			index = document.getElementById("waterId").selectedIndex;
																			waterIdText = waterId[index].text;
																			// var meterreader = glbToken.split("-")[0];
																			if (getNextUser(userId, waterIdText, glbToken).status == "ok") {
																				var nextuserid = getNextUser(userId, waterIdText, glbToken).nextuserid;
																				var nextwaterid = getNextUser(userId, waterIdText, glbToken).nextwaterid;
																				$("#userId").val(nextuserid);
																				$("#waterId option[value != 0]").remove();
																				$("#waterId").append("<option selected='selected'>" + nextwaterid + "</option>");
																	
																				// 查询结果
																				// 清空用水吨位的数据
																				var waterTonnage = document.getElementById("waterTonnage");
																				waterTonnage.innerText = " ";
																	
																				// 将用户号及水表号保存到临时input中
																				$("#userId_sto").val(nextuserid);
																				$("#waterId_sto").val(nextwaterid);
																				// 关闭loading
																				setTimeout(function() {
																					if (($("#userId_sto").val() && $("#waterId_sto").val()) != "") {
																						mui.hideLoading();
																					}
																				}, 500);
																				// 
																				var userWaterData = getUseWaterData(nextuserid, nextwaterid, glbToken);
																				if (userWaterData.status == "error") {
																					if (userId == "") {
																						mui.hideLoading();
																						alert("用户号不能为空！");
																					} else {
																						mui.hideLoading();
																						alert("无此用户");
																					}
																					// alert("无此用户");
																				} else if (userWaterData.status == "tips") {
																					var userName = document.getElementById("userName");
																					userName.innerText = " ";
																					var meterReadingDate = document.getElementById("meterReadingDate");
																					meterReadingDate.innerText = " ";
																					var lastMonthCode = document.getElementById("lastMonthCode");
																					lastMonthCode.innerText = " ";
																					var meterReading = document.getElementById("meterReading");
																					meterReading.innerText = " ";
																					var useraddress = document.getElementById("useraddress");
																					useraddress.innerText = " ";
																					var waterfactorid = document.getElementById('waterfactorid');
																					waterfactorid.innerText = " ";
																					$("#submit").text("保存");
																					alert("本月抄表已提交处理！无需再次录入");
																				} else {
																					// 修改提交按钮的值
																					if (userWaterData.isnew == 0) {
																	
																						var thisMonth = userWaterData.thismonthcode;
																						// var estimateTonnage = $("#estimateTonnage").val();
																						var pre = userWaterData.precheckcode;
																						var after = userWaterData.aftercheckcode;
																						var offSet = userWaterData.offset;
																						var memo = userWaterData.memo;
																						// 用水吨位计算
																						var waterTonnage = document.getElementById("waterTonnage");
																						var start_stop = thisMonth.toString() - userWaterData.lastmonthcode;
																						var pre_after = pre.toString() - after.toString();
																						waterTonnage.innerText = start_stop + pre_after;
																						// 将已录入抄码数填充到本月抄码input中
																						$("#thisMonth").val(thisMonth);
																						$("#estimateTonnage").val(userWaterData.estimatetonnage);
																						$("#pre").val(pre);
																						$("#after").val(after);
																						$("#offSet").val(offSet);
																						$("#memo").val(memo);
																	
																						$("#submit").text("更新提交");
																					} else if (userWaterData.isnew == 1) {
																						$("#thisMonth").val("");
																						$("#estimateTonnage").val(0);
																						$("#pre").val(0);
																						$("#after").val(0);
																						$("#offSet").val(0);
																						$("#memo").val('');
																						$("#submit").text("新增提交");
																					} else {
																						$("#submit").text("提交");
																					}
																					var userName = document.getElementById("userName");
																					userName.innerText = userWaterData.username;
																					var meterReadingDate = document.getElementById("meterReadingDate");
																					meterReadingDate.innerText = userWaterData.currentmonth;
																					var lastMonthCode = document.getElementById("lastMonthCode");
																					lastMonthCode.innerText = userWaterData.lastmonthcode;
																					var meterReading = document.getElementById("meterReading");
																					meterReading.innerText = userWaterData.meterreader;
																					var useraddress = document.getElementById("useraddress");
																					useraddress.innerText = userWaterData.useraddress;
																					var waterfactorid = document.getElementById('waterfactorid');
																					waterfactorid.innerText = userWaterData.waterfactorid;
																				}
																			} else {
																				setTimeout(function() {
																					// if (($("#userId_sto").val() && $("#waterId_sto").val()) != "") {
																					mui.hideLoading();
																					alert("该用户已经是最后一个了！");
																				}, 500);
																	
																			}
																		}
																	} else {
																		// var meterreader = glbToken.split("-")[0];
																		// alert(meterreader)
																		if (getNextUser(userId, waterIdText, glbToken).status == "ok") {
																			var nextuserid = getNextUser(userId, waterIdText, glbToken).nextuserid;
																			var nextwaterid = getNextUser(userId, waterIdText, glbToken).nextwaterid;
																			$("#userId").val(nextuserid);
																			$("#waterId option[value != 0]").remove();
																			$("#waterId").append("<option selected='selected'>" + nextwaterid + "</option>");
																	
																			// 查询结果
																			// 清空用水吨位的数据
																			var waterTonnage = document.getElementById("waterTonnage");
																			waterTonnage.innerText = " ";
																	
																			// 将用户号及水表号保存到临时input中
																			$("#userId_sto").val(nextuserid);
																			$("#waterId_sto").val(nextwaterid);
																			// 关闭loading
																			setTimeout(function() {
																				if (($("#userId_sto").val() && $("#waterId_sto").val()) != "") {
																					mui.hideLoading();
																				}
																			}, 500);
																			// 
																			var userWaterData = getUseWaterData(nextuserid, nextwaterid, glbToken);
																			if (userWaterData.status == "error") {
																				if (userId == "") {
																					mui.hideLoading();
																					alert("用户号不能为空");
																				} else {
																					mui.hideLoading();
																					alert("无此用户");
																				}
																				// alert("无此用户");
																			} else if (userWaterData.status == "tips") {
																				var userName = document.getElementById("userName");
																				userName.innerText = " ";
																				var meterReadingDate = document.getElementById("meterReadingDate");
																				meterReadingDate.innerText = " ";
																				var lastMonthCode = document.getElementById("lastMonthCode");
																				lastMonthCode.innerText = " ";
																				var meterReading = document.getElementById("meterReading");
																				meterReading.innerText = " ";
																				var useraddress = document.getElementById("useraddress");
																				useraddress.innerText = " ";
																				var waterfactorid = document.getElementById('waterfactorid');
																				waterfactorid.innerText = " ";
																				$("#submit").text("保存");
																				alert("本月抄表已提交处理！无需再次录入");
																			} else {
																				// 修改提交按钮的值
																				if (userWaterData.isnew == 0) {
																	
																					var thisMonth = userWaterData.thismonthcode;
																					// var estimateTonnage = $("#estimateTonnage").val();
																					var pre = userWaterData.precheckcode;
																					var after = userWaterData.aftercheckcode;
																					var offSet = userWaterData.offset;
																					var memo = userWaterData.memo;
																					// 用水吨位计算
																					var waterTonnage = document.getElementById("waterTonnage");
																					var start_stop = thisMonth.toString() - userWaterData.lastmonthcode;
																					var pre_after = pre.toString() - after.toString();
																					waterTonnage.innerText = start_stop + pre_after;
																					// 将已录入抄码数填充到本月抄码input中
																					$("#thisMonth").val(thisMonth);
																					$("#estimateTonnage").val(userWaterData.estimatetonnage);
																					$("#pre").val(pre);
																					$("#after").val(after);
																					$("#offSet").val(offSet);
																					$("#memo").val(memo);
																	
																					$("#submit").text("更新提交");
																				} else if (userWaterData.isnew == 1) {
																					$("#thisMonth").val("");
																					$("#estimateTonnage").val(0);
																					$("#pre").val(0);
																					$("#after").val(0);
																					$("#offSet").val(0);
																					$("#memo").val('');
																					$("#submit").text("新增提交");
																				} else {
																					$("#submit").text("提交");
																				}
																				var userName = document.getElementById("userName");
																				userName.innerText = userWaterData.username;
																				var meterReadingDate = document.getElementById("meterReadingDate");
																				meterReadingDate.innerText = userWaterData.currentmonth;
																				var lastMonthCode = document.getElementById("lastMonthCode");
																				lastMonthCode.innerText = userWaterData.lastmonthcode;
																				var meterReading = document.getElementById("meterReading");
																				meterReading.innerText = userWaterData.meterreader;
																				var useraddress = document.getElementById("useraddress");
																				useraddress.innerText = userWaterData.useraddress;
																				var waterfactorid = document.getElementById('waterfactorid');
																				waterfactorid.innerText = userWaterData.waterfactorid;
																			}
																		} else {
																			setTimeout(function() {
																				// if (($("#userId_sto").val() && $("#waterId_sto").val()) != "") {
																				mui.hideLoading();
																				alert("该用户已经是最后一个了！");
																				// }
																			}, 500);
																	
																		}
																	}
																	
																}, 300);
																$("#thisMonth").val("");
															} else {
																alert("新增失败");
															}
														} else {
															plus.nativeUI.alert('位置信息保存失败')
															// return
														}
														plus.nativeUI.closeWaiting();
													}, function(e) {
														alert('Geolocation error: ' + e.message)
													}, {
														provider: 'baidu'
													});
													plus.nativeUI.closeWaiting()
												} else {
													mui.toast("请先开启位置服务");
													plus.nativeUI.closeWaiting()
													// 防止重复点击提交按钮移除事件
													$("#submit").attr("disabled", false);
													mui.hideLoading();
													// return;
												}
											}
										} else {
											return
										}
									})
								} else {
									// 获取抄表位置信息
									plus.nativeUI.showWaiting("正在定位...", {
										padlock: false
									});
									if (plus.os.name == "Android") {
										var context = plus.android.importClass("android.content.Context");
										var locationManager = plus.android.importClass("android.location.LocationManager");
										var main = plus.android.runtimeMainActivity();
										var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
										androidIsOpen = mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER);
										if (androidIsOpen) {
											plus.geolocation.getCurrentPosition(function(p) {
												var latitude = p.coords.latitude;
												var longitude = p.coords.longitude;
												var altitude = p.coords.altitude;
												var geolocationInfo = saveCoord(staffid, userId, longitude, latitude, altitude, glbToken);
												if (geolocationInfo.status == 'ok') {
													// 插入操作
													var addData = AddUseWaterData(userId, waterIdText, userWaterData.currentmonth, userWaterData.lastmonthcode,
														thisMonth, pre, after, estimateTonnage, offSet, glbToken, memo);
													if (addData.status == "ok") {
														setTimeout(function() {
															// mui.hideLoading();
															mui.toast('新增成功',{ duration:'short', type:'div' });
															if (start_stop + pre_after >= 0) {
																waterTonnage.innerText = start_stop + pre_after;
															}
															
															// 新增成功后直接查找下一户
															var userId = $("#userId").val();
															
															// var waterId = document.getElementById("waterId");
															// var index = waterId.selectedIndex;
															// var waterIdText = waterId[index].text;
															var waterIdText = $("#waterId option:selected").text();
															if (waterIdText == "请选择水表号") {
																var waterIdList = getWaterIDList(userId, glbToken);
																if (waterIdList.length == 0) {
																	// mui.hideLoading();
																	alert("请您检查用户号是否正确");
																	// $("#waterId").append("<option value='0'>" + "请选择水表号" + "</option>");
																} else {
																	// for (var i = 0; i < waterIdList.length; i++) {
																	// 	$("#waterId").append("<option selected='selected'>" + waterIdList[i].WaterID + "</option>");
																	// }
															
																	// 有两个水表号的均以第一个为查询基础
																	$("#waterId").append("<option selected='selected'>" + waterIdList[0].WaterID + "</option>");
															
																	// $("#waterId option[value = 0]").remove();
																	index = document.getElementById("waterId").selectedIndex;
																	waterIdText = waterId[index].text;
																	// var meterreader = glbToken.split("-")[0];
																	if (getNextUser(userId, waterIdText, glbToken).status == "ok") {
																		var nextuserid = getNextUser(userId, waterIdText, glbToken).nextuserid;
																		var nextwaterid = getNextUser(userId, waterIdText, glbToken).nextwaterid;
																		$("#userId").val(nextuserid);
																		$("#waterId option[value != 0]").remove();
																		$("#waterId").append("<option selected='selected'>" + nextwaterid + "</option>");
															
																		// 查询结果
																		// 清空用水吨位的数据
																		var waterTonnage = document.getElementById("waterTonnage");
																		waterTonnage.innerText = " ";
															
																		// 将用户号及水表号保存到临时input中
																		$("#userId_sto").val(nextuserid);
																		$("#waterId_sto").val(nextwaterid);
																		// 关闭loading
																		setTimeout(function() {
																			if (($("#userId_sto").val() && $("#waterId_sto").val()) != "") {
																				mui.hideLoading();
																			}
																		}, 500);
																		// 
																		var userWaterData = getUseWaterData(nextuserid, nextwaterid, glbToken);
																		if (userWaterData.status == "error") {
																			if (userId == "") {
																				mui.hideLoading();
																				alert("用户号不能为空！");
																			} else {
																				mui.hideLoading();
																				alert("无此用户");
																			}
																			// alert("无此用户");
																		} else if (userWaterData.status == "tips") {
																			var userName = document.getElementById("userName");
																			userName.innerText = " ";
																			var meterReadingDate = document.getElementById("meterReadingDate");
																			meterReadingDate.innerText = " ";
																			var lastMonthCode = document.getElementById("lastMonthCode");
																			lastMonthCode.innerText = " ";
																			var meterReading = document.getElementById("meterReading");
																			meterReading.innerText = " ";
																			var useraddress = document.getElementById("useraddress");
																			useraddress.innerText = " ";
																			var waterfactorid = document.getElementById('waterfactorid');
																			waterfactorid.innerText = " ";
																			$("#submit").text("保存");
																			alert("本月抄表已提交处理！无需再次录入");
																		} else {
																			// 修改提交按钮的值
																			if (userWaterData.isnew == 0) {
															
																				var thisMonth = userWaterData.thismonthcode;
																				// var estimateTonnage = $("#estimateTonnage").val();
																				var pre = userWaterData.precheckcode;
																				var after = userWaterData.aftercheckcode;
																				var offSet = userWaterData.offset;
																				var memo = userWaterData.memo;
																				// 用水吨位计算
																				var waterTonnage = document.getElementById("waterTonnage");
																				var start_stop = thisMonth.toString() - userWaterData.lastmonthcode;
																				var pre_after = pre.toString() - after.toString();
																				waterTonnage.innerText = start_stop + pre_after;
																				// 将已录入抄码数填充到本月抄码input中
																				$("#thisMonth").val(thisMonth);
																				$("#estimateTonnage").val(userWaterData.estimatetonnage);
																				$("#pre").val(pre);
																				$("#after").val(after);
																				$("#offSet").val(offSet);
																				$("#memo").val(memo);
															
																				$("#submit").text("更新提交");
																			} else if (userWaterData.isnew == 1) {
																				$("#thisMonth").val("");
																				$("#estimateTonnage").val(0);
																				$("#pre").val(0);
																				$("#after").val(0);
																				$("#offSet").val(0);
																				$("#memo").val('');
																				$("#submit").text("新增提交");
																			} else {
																				$("#submit").text("提交");
																			}
																			var userName = document.getElementById("userName");
																			userName.innerText = userWaterData.username;
																			var meterReadingDate = document.getElementById("meterReadingDate");
																			meterReadingDate.innerText = userWaterData.currentmonth;
																			var lastMonthCode = document.getElementById("lastMonthCode");
																			lastMonthCode.innerText = userWaterData.lastmonthcode;
																			var meterReading = document.getElementById("meterReading");
																			meterReading.innerText = userWaterData.meterreader;
																			var useraddress = document.getElementById("useraddress");
																			useraddress.innerText = userWaterData.useraddress;
																			var waterfactorid = document.getElementById('waterfactorid');
																			waterfactorid.innerText = userWaterData.waterfactorid;
																		}
																	} else {
																		setTimeout(function() {
																			// if (($("#userId_sto").val() && $("#waterId_sto").val()) != "") {
																			mui.hideLoading();
																			alert("该用户已经是最后一个了！");
																		}, 500);
															
																	}
																}
															} else {
																// var meterreader = glbToken.split("-")[0];
																// alert(meterreader)
																if (getNextUser(userId, waterIdText, glbToken).status == "ok") {
																	var nextuserid = getNextUser(userId, waterIdText, glbToken).nextuserid;
																	var nextwaterid = getNextUser(userId, waterIdText, glbToken).nextwaterid;
																	$("#userId").val(nextuserid);
																	$("#waterId option[value != 0]").remove();
																	$("#waterId").append("<option selected='selected'>" + nextwaterid + "</option>");
															
																	// 查询结果
																	// 清空用水吨位的数据
																	var waterTonnage = document.getElementById("waterTonnage");
																	waterTonnage.innerText = " ";
															
																	// 将用户号及水表号保存到临时input中
																	$("#userId_sto").val(nextuserid);
																	$("#waterId_sto").val(nextwaterid);
																	// 关闭loading
																	setTimeout(function() {
																		if (($("#userId_sto").val() && $("#waterId_sto").val()) != "") {
																			mui.hideLoading();
																		}
																	}, 500);
																	// 
																	var userWaterData = getUseWaterData(nextuserid, nextwaterid, glbToken);
																	if (userWaterData.status == "error") {
																		if (userId == "") {
																			mui.hideLoading();
																			alert("用户号不能为空");
																		} else {
																			mui.hideLoading();
																			alert("无此用户");
																		}
																		// alert("无此用户");
																	} else if (userWaterData.status == "tips") {
																		var userName = document.getElementById("userName");
																		userName.innerText = " ";
																		var meterReadingDate = document.getElementById("meterReadingDate");
																		meterReadingDate.innerText = " ";
																		var lastMonthCode = document.getElementById("lastMonthCode");
																		lastMonthCode.innerText = " ";
																		var meterReading = document.getElementById("meterReading");
																		meterReading.innerText = " ";
																		var useraddress = document.getElementById("useraddress");
																		useraddress.innerText = " ";
																		var waterfactorid = document.getElementById('waterfactorid');
																		waterfactorid.innerText = " ";
																		$("#submit").text("保存");
																		alert("本月抄表已提交处理！无需再次录入");
																	} else {
																		// 修改提交按钮的值
																		if (userWaterData.isnew == 0) {
															
																			var thisMonth = userWaterData.thismonthcode;
																			// var estimateTonnage = $("#estimateTonnage").val();
																			var pre = userWaterData.precheckcode;
																			var after = userWaterData.aftercheckcode;
																			var offSet = userWaterData.offset;
																			var memo = userWaterData.memo;
																			// 用水吨位计算
																			var waterTonnage = document.getElementById("waterTonnage");
																			var start_stop = thisMonth.toString() - userWaterData.lastmonthcode;
																			var pre_after = pre.toString() - after.toString();
																			waterTonnage.innerText = start_stop + pre_after;
																			// 将已录入抄码数填充到本月抄码input中
																			$("#thisMonth").val(thisMonth);
																			$("#estimateTonnage").val(userWaterData.estimatetonnage);
																			$("#pre").val(pre);
																			$("#after").val(after);
																			$("#offSet").val(offSet);
																			$("#memo").val(memo);
															
																			$("#submit").text("更新提交");
																		} else if (userWaterData.isnew == 1) {
																			$("#thisMonth").val("");
																			$("#estimateTonnage").val(0);
																			$("#pre").val(0);
																			$("#after").val(0);
																			$("#offSet").val(0);
																			$("#memo").val('');
																			$("#submit").text("新增提交");
																		} else {
																			$("#submit").text("提交");
																		}
																		var userName = document.getElementById("userName");
																		userName.innerText = userWaterData.username;
																		var meterReadingDate = document.getElementById("meterReadingDate");
																		meterReadingDate.innerText = userWaterData.currentmonth;
																		var lastMonthCode = document.getElementById("lastMonthCode");
																		lastMonthCode.innerText = userWaterData.lastmonthcode;
																		var meterReading = document.getElementById("meterReading");
																		meterReading.innerText = userWaterData.meterreader;
																		var useraddress = document.getElementById("useraddress");
																		useraddress.innerText = userWaterData.useraddress;
																		var waterfactorid = document.getElementById('waterfactorid');
																		waterfactorid.innerText = userWaterData.waterfactorid;
																	}
																} else {
																	setTimeout(function() {
																		// if (($("#userId_sto").val() && $("#waterId_sto").val()) != "") {
																		mui.hideLoading();
																		alert("该用户已经是最后一个了！");
																		// }
																	}, 500);
															
																}
															}
															
														}, 300);
														$("#thisMonth").val("");
													} else {
														alert("新增失败");
													}
												} else {
													plus.nativeUI.alert('位置信息保存失败')
													return
												}
												plus.nativeUI.closeWaiting();
											}, function(e) {
												alert('Geolocation error: ' + e.message)
											}, {
												provider: 'baidu'
											});
											plus.nativeUI.closeWaiting()
										} else {
											mui.toast("请先开启位置服务");
											plus.nativeUI.closeWaiting()
											// 防止重复点击提交按钮移除事件
											$("#submit").attr("disabled", false);
											mui.hideLoading();
											return;
										}
									}
								}
							} else {
								alert("本月抄码不能为空且必须大于本月起码");
							}
						} else {
							alert("请您先查询获取抄表情况！");
						}
						
						// 防止重复点击提交按钮移除事件
						$("#submit").attr("disabled", false);
						
					} else {
						app.setState({});
						plus.webview.getLaunchWebview().show("pop-in");
						setTimeout(function() {
							alert("此账号已在其他设备登录,请重新登录!");
							localStorage.clear();
							plus.runtime.restart();
						}, 30)
					}
				})
			});
		</script>
	</body>
</html>
